package demo07.remote.control;

import demo07.remote.commandImp.Command;
import demo07.remote.nocommand.NoCommand;

public class RemoteControl {
	Command[] onCommands;
	Command[] offCommands;
 
	public RemoteControl() {
		onCommands = new Command[7];
		offCommands = new Command[7];
		
		//初始化为空（2个数组各7个）
		Command noCommand = new NoCommand();
		for (int i = 0; i < 7; i++) {
			onCommands[i] = noCommand;
			offCommands[i] = noCommand;
		}
	}
							  //位置               //打开命令                                       //关闭命令
	public void setCommand(int slot, Command onCommand, Command offCommand) {
		onCommands[slot] = onCommand;
		offCommands[slot] = offCommand;
	}
 
	//打开按钮
	public void onButtonWasPushed(int slot) {
		onCommands[slot].execute();
	}
	//关闭按钮
	public void offButtonWasPushed(int slot) {
		offCommands[slot].execute();
	}
  
	//重写toString
	public String toString() {
		StringBuffer stringBuff = new StringBuffer();
		stringBuff.append("\n------ 远程控制 -------\n");
		for (int i = 0; i < onCommands.length; i++) {
			stringBuff.append("[位置 " + i + "] " +"开启类"+ onCommands[i].getClass().getName()
				+ "   关闭类 " + offCommands[i].getClass().getName() + "\n");
		}
		return stringBuff.toString();
	}
	

}
